//
//  LSRadarView.m
//  ChartDemo
//
//  Created by 盛超 on 2018/10/24.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSRadarView.h"
#import "UIColor+RGB.h"

#define RADAR_RADIUS 120.0 //半径
#define huDuFromdu(du) M_PI/(180/du) //度转弧度
@interface LSRadarView () <CAAnimationDelegate>

@property (nonatomic,assign) CGPoint centerPoint;
/** self 的宽度 */
@property (nonatomic,assign) CGSize radarview_size;

//能力名称的位置坐标数组
@property (nonatomic,strong) NSArray *titlePoint_array;
//各能力位置坐标数组
@property (nonatomic,strong) NSArray *valuePoint_array;
//各达标值位置坐标数组
@property (nonatomic,strong) NSArray *standardPoint_array;
//各能力数字显示位置坐标数组
@property (nonatomic,strong) NSArray *valueTitlePoint_array;

/**
 显示文字信息,数据信息
 */
@property (nonatomic,strong) UIView *backView1;
/**
 高亮指示圆点
 */
@property (nonatomic,strong) UIImageView *indicatorView;
/**
 截取渐变路径的layer
 */
@property (nonatomic,strong) CAShapeLayer *shapeLayer;

@property (nonatomic,assign) BOOL needraw;


@end

@implementation LSRadarView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
       // [self setupUI];
        _needraw = YES;
    }
    return self;
}

- (void)setTitle_array:(NSArray *)title_array {
    _title_array = title_array;
    [self setupUI];
}

- (void)setupUI {
    _centerPoint = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    _cirlColor = [UIColor colorWithRed:27/255.0 green:152/255.0 blue:247/255.0 alpha:1];
//    _value_array = @[@"40",@"50",@"80",@"70",@"90"];
//    _title_array = @[@"听力",@"词汇",@"口语",@"发音",@"朗读"];
    
    [self setupTitleLabel];
    
}

- (void)setupTitleLabel {
    CGPoint center = self.centerPoint;
    CGPoint point1 = CGPointMake(center.x, center.y-(RADAR_RADIUS+25));
    CGPoint point2 = CGPointMake(center.x+sin(huDuFromdu(72))*(RADAR_RADIUS+25), center.y-sin(huDuFromdu(18))*(RADAR_RADIUS+25));
    CGPoint point3 = CGPointMake(center.x+sin(huDuFromdu(36))*(RADAR_RADIUS+25), center.y+sin(huDuFromdu(54))*(RADAR_RADIUS+25));
    CGPoint point4 = CGPointMake(center.x-sin(huDuFromdu(36))*(RADAR_RADIUS+25), center.y+sin(huDuFromdu(54))*(RADAR_RADIUS+25));
    CGPoint point5 = CGPointMake(center.x-sin(huDuFromdu(72))*(RADAR_RADIUS+25), center.y-sin(huDuFromdu(18))*(RADAR_RADIUS+25));
    _titlePoint_array = @[@(point1),@(point2),@(point3),@(point4),@(point5)];
    
    _backView1 = [[UIView alloc] initWithFrame:self.bounds];
    [self addSubview:_backView1];
    
    //添加能力维度名称label
    for (NSInteger i = 0; i<_titlePoint_array.count; i++) {
        CGPoint point = ((NSValue*)_titlePoint_array[i]).CGPointValue;
        UILabel *titlelbael = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,50, 15)];
        titlelbael.font = [UIFont systemFontOfSize:10];
        titlelbael.textAlignment = NSTextAlignmentCenter;
        titlelbael.textColor = [UIColor whiteColor];
        titlelbael.text = _title_array[i];
        titlelbael.center = point;
        [_backView1 addSubview:titlelbael];
    }
    
    ///计算每个能力值/能力值显示位置的坐标
    [self getPointValue_array];
    [self getPointValueTitle_array];
    [self getStandardPoint_array];
    
    //添加能力值label
    for (NSInteger i = 0; i<_valueTitlePoint_array.count; i++) {
         CGPoint point = ((NSValue*)_valueTitlePoint_array[i]).CGPointValue;
        UILabel *titlelValuebael = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,50, 15)];
        titlelValuebael.font = [UIFont systemFontOfSize:10];
        titlelValuebael.textAlignment = NSTextAlignmentCenter;
        titlelValuebael.textColor = [UIColor whiteColor];
        titlelValuebael.text = _value_array[i];
        titlelValuebael.center = point;
        [_backView1 addSubview:titlelValuebael];
    }
    
    //红点
    self.indicatorView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,30,30)];
    self.indicatorView.image = [UIImage imageNamed:@"LS-选中红点"];
    self.indicatorView.center = ((NSValue*)_valuePoint_array.firstObject).CGPointValue;
    [_backView1 addSubview:self.indicatorView];
    [_backView1 bringSubviewToFront:self.indicatorView];
    
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.autoreverses = YES;
    scaleAnimation.fromValue = @1.0;
    scaleAnimation.toValue = @1.2;
    scaleAnimation.duration = 1.0;
    scaleAnimation.repeatCount = MAXFLOAT;
    [self.indicatorView.layer addAnimation:scaleAnimation forKey:@"indicatorViewScale"];
}

/*
 计算五边形的每个顶点坐标
 */
- (NSArray*)calculatePointsWithRadius:(CGFloat)radius {
    CGPoint center = self.centerPoint;
    CGPoint point1 = CGPointMake(center.x, center.y-radius);
    CGPoint point2 = CGPointMake(center.x+sin(huDuFromdu(72))*radius, center.y-sin(huDuFromdu(18))*radius);
    CGPoint point3 = CGPointMake(center.x+sin(huDuFromdu(36))*radius, center.y+sin(huDuFromdu(54))*radius);
    CGPoint point4 = CGPointMake(center.x-sin(huDuFromdu(36))*radius, center.y+sin(huDuFromdu(54))*radius);
    CGPoint point5 = CGPointMake(center.x-sin(huDuFromdu(72))*radius, center.y-sin(huDuFromdu(18))*radius);
    return @[@(point1),@(point2),@(point3),@(point4),@(point5)];
}

//添加每个点
- (void)addCircleAtPoint:(CGPoint)point {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 4, 4)];
    label.center = point;
    label.backgroundColor = [[UIColor colorWithHex:0xb4dcff] colorWithAlphaComponent:1];
    label.layer.cornerRadius = 2;
    label.layer.masksToBounds = YES;
    [self addSubview:label];
    
    //点闪烁动画
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.fromValue = @(0.3);
    opacityAnimation.toValue = @(1);
    opacityAnimation.autoreverses = YES;//动画执行完成后按原动画返回
    opacityAnimation.duration = 0.8;
    opacityAnimation.repeatCount = MAXFLOAT;
    [label.layer addAnimation:opacityAnimation forKey:nil];
}


- (void)drawRect:(CGRect)rect {
    //绘制五边形
    if(_needraw) {
        _needraw = NO;
        
        [self addCircleAtPoint:self.centerPoint];
        
        NSArray *radiusArray = @[@120,@96,@72,@48,@24];
        
        for (NSInteger i = 0; i<radiusArray.count; i++) {
            
            NSArray *points = [self calculatePointsWithRadius:((NSNumber*)radiusArray[i]).floatValue];
            CGFloat alpha = 0;
            if (i==0) {
                alpha = 0.30;
            } else if(i==1) {
                alpha = 0.45;
            } else if (i==2) {
                alpha = 0.50;
            } else if (i==3) {
                alpha = 0.60 ;
            } else {
                alpha = 0.65;
            }
            //单个五边形
            [self drawLineWithPoints:points alpha:alpha WithIndex:i];
            
            if (i==0) {
                UIBezierPath *path = [UIBezierPath bezierPath];
                path.lineWidth = 0.5;
                [path moveToPoint:self.centerPoint];
                for (NSInteger i = 0; i<points.count; i++) {
                    CGPoint point = ((NSValue*)points[i]).CGPointValue;
                    [path addLineToPoint:point];
                    [path addLineToPoint:self.centerPoint];
                }
                [path closePath];
                [[[UIColor whiteColor] colorWithAlphaComponent:0.3] setStroke];
                [path stroke];
            }
        }
        
        //    //绘制能力图谱（渐变遮罩区域）
        //    [self drawPath];
        //
        //    [self bringSubviewToFront:_backView1];
    }
}

//绘制单个五边形
- (void)drawLineWithPoints:(NSArray*)points alpha:(CGFloat)alpha WithIndex:(NSInteger)i{
    
    CGFloat lineWidth = 2.0-0.4*i;//线宽
    UIBezierPath *path = [UIBezierPath bezierPath];
    path.lineWidth = lineWidth;
    for (NSInteger i = 0; i<points.count; i++) {
        
        CGPoint point = ((NSValue*)points[i]).CGPointValue;
        
        [self addCircleAtPoint:point];
        
        if (i==0) {
            [path moveToPoint:point];
        } else {
            [path addLineToPoint:point];
        }
        
    }
    [path closePath];
    
    //五边形阴影
    CAShapeLayer *shape3Layer = [CAShapeLayer layer];
    shape3Layer.lineWidth = lineWidth;//0.5;
    //shape2Layer.lineDashPattern = @[@1,@2];
    shape3Layer.opacity = alpha;
    shape3Layer.path = path.CGPath;
    shape3Layer.strokeColor = [UIColor whiteColor].CGColor;
    shape3Layer.fillColor = [[UIColor colorWithHex:0x0d9ff3] colorWithAlphaComponent:0.15].CGColor;
    [self.layer addSublayer:shape3Layer];
    shape3Layer.shadowOffset = CGSizeMake(0,5);
    shape3Layer.shadowRadius = 2;
    shape3Layer.shadowColor = [UIColor blackColor].CGColor;
    shape3Layer.shadowOpacity = 0.3;
}

//绘制能力图谱（渐变遮罩区域）
- (void)drawPath {
    if(!_valuePoint_array) {
        [self getPointValue_array];
    }
    //路径
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    for (NSInteger i = 0; i<self.valuePoint_array.count; i++) {
        CGPoint point = [[self.valuePoint_array objectAtIndex:i] CGPointValue];
        if (i == 0) {
            [bezierPath moveToPoint:point];
        } else {
            [bezierPath addLineToPoint:point];
        }
    }
    CGPoint point = [[self.valuePoint_array objectAtIndex:0] CGPointValue];
    [bezierPath addLineToPoint:point];
    [bezierPath closePath];
    
    //外围连线
    CAShapeLayer *shape2Layer = [CAShapeLayer layer];
   // self.shape2Layer = shape2Layer;
    shape2Layer.lineWidth = 1.5;
    shape2Layer.lineDashPattern = @[@1.5,@2];
    shape2Layer.path = bezierPath.CGPath;
    shape2Layer.strokeColor = [UIColor whiteColor].CGColor;
    shape2Layer.fillColor = [UIColor clearColor].CGColor;
   // [self.layer addSublayer:shape2Layer];
    
    //渐变色
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.locations = @[@0.2,@0.5,@1.0];
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(0, 0);
    gradientLayer.colors = @[(__bridge id)[[UIColor colorWithHex:0x82c2ff] colorWithAlphaComponent:0].CGColor,
                             (__bridge id)[[UIColor colorWithHex:0xffffff] colorWithAlphaComponent:0.3].CGColor,
                             (__bridge id)[[UIColor colorWithHex:0xffffff] colorWithAlphaComponent:1].CGColor];
    gradientLayer.frame = self.bounds;
    
    //截取渐变色路径layer
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = bezierPath.CGPath;
    shapeLayer.strokeColor = [UIColor whiteColor].CGColor;
    shapeLayer.fillColor = [UIColor whiteColor].CGColor;
    gradientLayer.mask = shapeLayer;
    [self.layer addSublayer:gradientLayer];
    
    //渐变色路径动画
    UIBezierPath *bezierPath_zero = [UIBezierPath bezierPath];
    for (NSInteger i = 0; i<self.valuePoint_array.count; i++) {
        CGPoint point = self.centerPoint;
        if (i == 0) {
            [bezierPath_zero moveToPoint:point];
        } else {
            [bezierPath_zero addLineToPoint:point];
        }
    }
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
    pathAnimation.fromValue = (id)(bezierPath_zero.CGPath);
    pathAnimation.toValue = (id)(bezierPath.CGPath);
    pathAnimation.duration = 0.5;
    pathAnimation.repeatCount = 1;
    [shapeLayer addAnimation:pathAnimation forKey:nil];
    
    //添加虚线
    [self addDashPatternLine];
    
}

//添加虚线
- (void)addDashPatternLine {
    
    for (NSInteger i = 0; i<self.valuePoint_array.count; i++) {
        UIBezierPath *bezierPath = [UIBezierPath bezierPath];
        CGPoint point = [[self.valuePoint_array objectAtIndex:i] CGPointValue];
        CGPoint point2;
        if(i==self.valuePoint_array.count-1) {
            point2 = [[self.valuePoint_array objectAtIndex:0] CGPointValue];
        } else {
            point2 = [[self.valuePoint_array objectAtIndex:i+1] CGPointValue];
        }
        
        [bezierPath moveToPoint:point];
        [bezierPath addLineToPoint:point2];
        
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.lineWidth = 1.5;
        shapeLayer.lineDashPattern = @[@1.5,@2];
        shapeLayer.path = bezierPath.CGPath;
        shapeLayer.strokeColor = [UIColor whiteColor].CGColor;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        [self.layer addSublayer:shapeLayer];
        
        //虚线动画
        CABasicAnimation *strokeAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        strokeAnimation.duration = 1.0;
        strokeAnimation.autoreverses = NO;
        strokeAnimation.repeatCount = 1;
        strokeAnimation.fromValue = @(0);
        strokeAnimation.toValue = @(1);
        [shapeLayer addAnimation:strokeAnimation forKey:nil];
    }
    
}

//绘制达标线
- (void)drawStandardPath {
    //路径
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    for (NSInteger i = 0; i<self.standardPoint_array.count; i++) {
        CGPoint point = [[self.standardPoint_array objectAtIndex:i] CGPointValue];
        if (i == 0) {
            [bezierPath moveToPoint:point];
        } else {
            [bezierPath addLineToPoint:point];
        }
    }
    CGPoint point = [[self.standardPoint_array objectAtIndex:0] CGPointValue];
    [bezierPath addLineToPoint:point];
    [bezierPath closePath];
    
    //外围连线
    CAShapeLayer *shape2Layer = [CAShapeLayer layer];
    // self.shape2Layer = shape2Layer;
    shape2Layer.lineWidth = 1.0;
    shape2Layer.path = bezierPath.CGPath;
    shape2Layer.strokeColor =[UIColor colorWithHex:0x49c537].CGColor; //[[UIColor orangeColor] colorWithAlphaComponent:1].CGColor;
    shape2Layer.fillColor = [[UIColor colorWithHex:0x49c537] colorWithAlphaComponent:0.5].CGColor;//[[UIColor orangeColor] colorWithAlphaComponent:0.5].CGColor;//[UIColor clearColor].CGColor;
    
    CABasicAnimation *strokeAni = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    strokeAni.duration = 1.0;
    strokeAni.fromValue = @0;
    strokeAni.toValue = @1;
    [shape2Layer addAnimation:strokeAni forKey:nil];
    
    [self.layer addSublayer:shape2Layer];
}

//计算每个能力值的坐标
- (void)getPointValue_array {
    CGPoint center = self.centerPoint;
    CGPoint point1 = CGPointMake(center.x, center.y-((NSString*)_value_array[0]).floatValue/100 * RADAR_RADIUS);
    CGPoint point2 = CGPointMake(center.x+sin(huDuFromdu(72))*((NSString*)_value_array[1]).floatValue/100 * RADAR_RADIUS, center.y-sin(huDuFromdu(18))*((NSString*)_value_array[1]).floatValue/100 * RADAR_RADIUS);
    CGPoint point3 = CGPointMake(center.x+sin(huDuFromdu(36))*((NSString*)_value_array[2]).floatValue/100 * RADAR_RADIUS, center.y+sin(huDuFromdu(54))*((NSString*)_value_array[2]).floatValue/100 * RADAR_RADIUS);
    CGPoint point4 = CGPointMake(center.x-sin(huDuFromdu(36))*((NSString*)_value_array[3]).floatValue/100 * RADAR_RADIUS, center.y+sin(huDuFromdu(54))*((NSString*)_value_array[3]).floatValue/100 * RADAR_RADIUS);
    CGPoint point5 = CGPointMake(center.x-sin(huDuFromdu(72))*((NSString*)_value_array[4]).floatValue/100 * RADAR_RADIUS, center.y-sin(huDuFromdu(18))*((NSString*)_value_array[4]).floatValue/100 * RADAR_RADIUS);
    _valuePoint_array = @[@(point1),@(point2),@(point3),@(point4),@(point5)];
}

//计算每个能力值名称的坐标
- (void)getPointValueTitle_array {
    CGPoint center = self.centerPoint;
    CGPoint point1 = CGPointMake(center.x, center.y-(((NSString*)_value_array[0]).floatValue+2.5)/100 * (RADAR_RADIUS+20));
    CGPoint point2 = CGPointMake(center.x+sin(huDuFromdu(72))*(((NSString*)_value_array[1]).floatValue+2.5)/100 * (RADAR_RADIUS+20), center.y-sin(huDuFromdu(18))*(((NSString*)_value_array[1]).floatValue+2.5)/100 * (RADAR_RADIUS+20)+10);
    CGPoint point3 = CGPointMake(center.x+sin(huDuFromdu(36))*(((NSString*)_value_array[2]).floatValue+2.5)/100 * (RADAR_RADIUS+20), center.y+sin(huDuFromdu(54))*(((NSString*)_value_array[2]).floatValue+2.5)/100 * (RADAR_RADIUS+20));
    CGPoint point4 = CGPointMake(center.x-sin(huDuFromdu(36))*(((NSString*)_value_array[3]).floatValue+2.5)/100 * (RADAR_RADIUS+20), center.y+sin(huDuFromdu(54))*(((NSString*)_value_array[3]).floatValue+2.5)/100 * (RADAR_RADIUS+20));
    CGPoint point5 = CGPointMake(center.x-sin(huDuFromdu(72))*(((NSString*)_value_array[4]).floatValue+2.5)/100 * (RADAR_RADIUS+20), center.y-sin(huDuFromdu(18))*(((NSString*)_value_array[4]).floatValue+2.5)/100 * (RADAR_RADIUS+20)+10);
    _valueTitlePoint_array = @[@(point1),@(point2),@(point3),@(point4),@(point5)];
}

//standardPoint_array
- (void)getStandardPoint_array {
    CGPoint center = self.centerPoint;
    CGPoint point1 = CGPointMake(center.x, center.y-((NSString*)_standardvalue_array[0]).floatValue/100 * RADAR_RADIUS);
    CGPoint point2 = CGPointMake(center.x+sin(huDuFromdu(72))*((NSString*)_standardvalue_array[1]).floatValue/100 * RADAR_RADIUS, center.y-sin(huDuFromdu(18))*((NSString*)_standardvalue_array[1]).floatValue/100 * RADAR_RADIUS);
    CGPoint point3 = CGPointMake(center.x+sin(huDuFromdu(36))*((NSString*)_standardvalue_array[2]).floatValue/100 * RADAR_RADIUS, center.y+sin(huDuFromdu(54))*((NSString*)_standardvalue_array[2]).floatValue/100 * RADAR_RADIUS);
    CGPoint point4 = CGPointMake(center.x-sin(huDuFromdu(36))*((NSString*)_standardvalue_array[3]).floatValue/100 * RADAR_RADIUS, center.y+sin(huDuFromdu(54))*((NSString*)_standardvalue_array[3]).floatValue/100 * RADAR_RADIUS);
    CGPoint point5 = CGPointMake(center.x-sin(huDuFromdu(72))*((NSString*)_standardvalue_array[4]).floatValue/100 * RADAR_RADIUS, center.y-sin(huDuFromdu(18))*((NSString*)_standardvalue_array[4]).floatValue/100 * RADAR_RADIUS);
    _standardPoint_array = @[@(point1),@(point2),@(point3),@(point4),@(point5)];
    
}


- (void)startMoveCircle:(NSInteger)index {
    
    [self.indicatorView.layer removeAnimationForKey:@"indicatorViewScale"];
    
    CGPoint point =  ((NSValue*)_valuePoint_array[index]).CGPointValue;
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.duration = 0.8;
    group.repeatCount = 1;
    group.delegate = self;
    
    CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    positionAnimation.duration = 0.8;
    positionAnimation.repeatCount = 1;
    positionAnimation.fromValue = @(self.indicatorView.layer.position);
    positionAnimation.toValue = @(point);
    positionAnimation.fillMode = kCAFillModeForwards;
    positionAnimation.removedOnCompletion = NO;
    self.indicatorView.layer.position = point;
    
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.duration = 0.8;
    scaleAnimation.repeatCount = 1;
    scaleAnimation.fromValue = @(1);
    scaleAnimation.toValue = @(1.3);
    scaleAnimation.autoreverses = YES;
    
    group.animations = @[positionAnimation,scaleAnimation];
    
    [self.indicatorView.layer addAnimation:group forKey:nil];
    self.indicatorView.layer.transform = CATransform3DScale(CATransform3DIdentity, 1, 1, 1);
}

- (void)startMainAnimation {
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.delegate = self;
    scaleAnimation.duration = 0.5;
    scaleAnimation.repeatCount = 1;
    scaleAnimation.fromValue = @(0);
    scaleAnimation.toValue = @(1);
    scaleAnimation.fillMode = kCAFillModeForwards;
    scaleAnimation.removedOnCompletion = NO;
    [self.layer addAnimation:scaleAnimation forKey:nil];
}

- (void)startSubAnimation {
    
    [self drawStandardPath];
    //绘制能力图谱（渐变遮罩区域）
    [self drawPath];
    
    [self bringSubviewToFront:_backView1];
    
}

- (void)stop {
    
}

- (void)startIndicatorViewScale {
    [self.indicatorView.layer removeAnimationForKey:@"indicatorViewScale"];
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.autoreverses = YES;
    scaleAnimation.fromValue = @1.0;
    scaleAnimation.toValue = @1.2;
    scaleAnimation.duration = 1.0;
    scaleAnimation.repeatCount = MAXFLOAT;
    [self.indicatorView.layer addAnimation:scaleAnimation forKey:@"indicatorViewScale"];
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    if (flag) {
       
        if ([anim isKindOfClass:[CAAnimationGroup class]]) {
            double delayInSeconds = 0.3;
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                //执行事件
                [self startIndicatorViewScale];
            });
           
            
        } else {
            
            [self startSubAnimation];
        }
        
    }
}

@end
